package com.ruoyi.plus.pub.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.plus.pub.domain.PubConfigPlus;
import com.ruoyi.plus.pub.mapper.PubConfigPlusMapper;
import com.ruoyi.plus.pub.service.IPubConfigPlusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统配置Service业务层处理
 *
 */
@Service
public class PubConfigPlusServiceImpl extends ServiceImpl<PubConfigPlusMapper, PubConfigPlus> implements IPubConfigPlusService {

    @Autowired
    private PubConfigPlusMapper pubConfigPlusMapper;

    /**
     * 查询系统配置列表
     *
     * @param pubConfigPlus 系统配置
     * @return 系统配置
     */
    @Override
    public List<PubConfigPlus> selectPubConfigList(PubConfigPlus pubConfigPlus) {
        return pubConfigPlusMapper.selectPubConfigList(pubConfigPlus);
    }

    @Override
    public boolean checkConfigKeyUnique(PubConfigPlus config) {
        long configId = StringUtils.isNull(config.getId()) ? -1L : config.getId();
        PubConfigPlus info = pubConfigPlusMapper.findByConfigKey(config.getConfigKey());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != configId) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    @Override
    public PubConfigPlus findByConfigKey(String key) {
        return pubConfigPlusMapper.findByConfigKey(key);
    }
}
